import Vue from 'vue'
import Vuex from 'vuex'
import {STORE,CACHE_KEY} from '@/constants'
import {BaseUtil} from '@zkwq/business'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user:BaseUtil.getStorage(CACHE_KEY.USER),
    roles:BaseUtil.getStorage(CACHE_KEY.ROLE),
    permissons:BaseUtil.getStorage(CACHE_KEY.PERMISSION),
    token:BaseUtil.getStorage(CACHE_KEY.TOKEN),
    oauthUri:null,
    topic:null,
    topicId:null,
    appid:null,
    clientType:null,
    theme:null,
    magazine:null,
  },
  getters: {
  },
  mutations: {
    [STORE.SET_PROPS]:(state,data) => {
      state.user = data.user;
      state.oauthUri = decodeURIComponent(data.oauthUri)
      state.appid = data.appid;
      state.topic = data.topic;
      state.topicId = data.topicId;
      state.clientType = data.clientType;
      state.theme = data.theme;
    },
    [STORE.SET_USER](state,user){
      state.user = user
    },[STORE.SET_TOKEN](state,token){
      state.token = token
    },[STORE.SET_ROLE](state,roles){
      state.roles = roles
    },[STORE.SET_PERMISSION](state,permissons){
      state.permissons = permissons
    },[STORE.SET_MAGAZINE](state,magazine){
      state.magazine = magazine
    }
  },
  actions: {
  },
  modules: {
  }
})
